chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.action === 'keyPressed') {
    console.log('收到按键消息:', message.key);
    
    chrome.storage.local.get('keyStats', (result) => {
      const stats = result.keyStats || {};
      stats[message.key] = (stats[message.key] || 0) + 1;
      
      chrome.storage.local.set({ keyStats: stats }, () => {
        console.log('数据已保存:', stats);
        sendResponse({ success: true });
      });
    });
    return true; // 保持消息通道开启
  }
}); 